package com.emoriarty.android.outilsresources.lists.overlaping;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.emoriarty.android.outilsresources.R;
import com.emoriarty.android.outilsresources.common.PlanetsAdapter;

public class MenuListFragment extends ListFragment {
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		String[] planets = getResources().getStringArray(R.array.planets);
		ArrayAdapter<String> menuAdapter = new PlanetsAdapter(getActivity(), planets);
		setListAdapter(menuAdapter);
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		switch (position) {
		case 2: replaceSubmenu(R.array.tierra); break;
		case 3: replaceSubmenu(R.array.marte); break;
		case 4: replaceSubmenu(R.array.jupiter); break;
		case 5: replaceSubmenu(R.array.saturno); break;
		case 6: replaceSubmenu(R.array.neptuno); break;
		case 7: replaceSubmenu(R.array.urano); break;
		default:break;
		}
	}
	
	private void replaceSubmenu(int idStringArray) {
		SubmenuListFragment submenu = new SubmenuListFragment();
		Bundle args = new Bundle();
		args.putStringArray(SubmenuListFragment.MOONS, getResources().getStringArray(idStringArray));
		submenu.setArguments(args);
		
		FragmentTransaction transaction = getFragmentManager().beginTransaction();
		transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
		transaction.replace(R.id.submenu, submenu);
		transaction.commit();
	}
}
